#!/usr/bin/python
# -*- coding: UTF-8 -*-

"""
@author: jiu
@contact: 643562684@qq.com
@time: 2022/3/10 15:08
"""

from typing import Union, Type
from Conf.setting import *
from selenium.webdriver import (Chrome, Firefox, Ie, Safari, Opera, Edge,
                                ChromeOptions, FirefoxOptions, IeOptions,
                                EdgeOptions)


class BrowserError(Exception):
    def __init__(self, msg):
        self._msg = msg

    def __str__(self):
        return r"Browser parameter selection error: {}".format(self._msg)


class BASE(object):
    # CHROME_PATH = CHROME_DRIVER_PATH
    CHROME_PATH = NEW_CHROME_DRIVER_PATH
    FIREFOX_PATH = FIREFOX_DRIVER_PATH
    IE_PATH = None
    # 是否添加option
    _option_mark = False
    _browser_mark = False

    def __init__(self, browser_type: Type[Union[Chrome, Firefox, Ie, Safari, Opera,]] = Chrome,
                 browser_option: Type[Union[ChromeOptions, FirefoxOptions]] = ChromeOptions,
                 driver_path: str = CHROME_PATH
                 ):
        if not issubclass(browser_type, (Chrome, Firefox, Ie, Safari, Opera, Edge)):
            raise BrowserError(browser_type)

        if not issubclass(browser_option, (ChromeOptions, FirefoxOptions, IeOptions,
                                           EdgeOptions)):
            raise BrowserError(browser_option)

        if not isinstance(driver_path, str):
            raise TypeError

        self._browser = browser_type
        self._option = browser_option
        self._driver_path = driver_path

    @property
    def option(self):
        pass

    @property
    def browser(self):
        pass
